package com.example.test.core.listener;

import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

@Component
public class Receiver {

    private static final Logger log = Logger.getLogger("Receiver");

    @RabbitListener(queues = "hello.queue.one")
    public Map<String, Object> processMessage1(String msg) {
        log.info(" 接收到来自hello.queue.one队列的消息：" + msg);
        Map<String, Object> map = new HashMap<>();
        map.put("result", true);
        map.put("message", "成功收到");
        return map;
    }

    @RabbitListener(queues = "hello.queue.two")
    public void processMessage2(Message message) {
        String messageStr = StringUtils.toEncodedString(message.getBody(), null);
        log.info(" 接收到来自hello.queue.two队列的消息：" + messageStr);
    }
}
